package br.com.jogo.services;

import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.math.Rectangle;

public class Camera2D extends OrthographicCamera {
	
	private final Rectangle rectangle;
	
	public final float frustumWidth;
	public final float frustumHeight;

	public Camera2D(float frustumWidth, float frustumHeight) {
		super(frustumWidth, frustumHeight);
		this.position.set(frustumWidth / 2, frustumHeight / 2, 0);
		this.frustumWidth = frustumWidth;
		this.frustumHeight = frustumHeight;		
		this.rectangle = new Rectangle(0, 0, frustumWidth, frustumHeight);

	}

	public Rectangle getRectangle() {
		this.rectangle.x = this.position.x - frustumWidth / 2;
		this.rectangle.y = this.position.y - frustumHeight / 2;

		return rectangle;
	}
	
	public void moveCam(float dx, float dy, float maxX, float maxY) {
		position.x += dx;
		position.y += dy;

		position.x = Math.max(frustumWidth * zoom / 2, position.x);
		position.y = Math.max(frustumHeight * zoom / 2, position.y);

		position.x = Math.min(maxX - (frustumWidth * zoom / 2), position.x);

		position.y = Math.min(maxY - (frustumHeight * zoom / 2), position.y);

	}

}
